<?php


namespace app\api\controller;


use app\common\controller\Api;

class Ocr extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 身份证识别
     */
    public function idcard()
    {
        $param = input('param.');
        $result = $this->validate($param,[
            'real_image'   => 'require|url',
            'id_card_side' => 'in:front,back'
        ]);

        if (true !== $result){
            $this->error($result);
        }
        $ocr = new \app\api\service\Ocr();
        $ocr->setImage(file_get_contents($param['real_image']));
        $result = $ocr->idcard($this->params['id_card_side'] ?? 'front');
        $this->success('',$result);
    }
}